package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVo;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    ApplicationService applicationService;
    @GetMapping("/select")
    public JsonResult selects(){
        log.debug("查询申请单");
        List<ApplicationVo> selects = applicationService.selects();
        return JsonResult.ok(selects);
    }
    @PostMapping("/save")
    public JsonResult save(ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请单: {}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        log.debug("保存成功");
        return JsonResult.ok();
    }
    @GetMapping("/select/search")
    public JsonResult selectSearch(ApplicationQuery applicationQuery){
        log.debug("查询申请单: {}",applicationQuery);
        List<ApplicationVo> selects = applicationService.selectSearch(applicationQuery);
        return JsonResult.ok(selects);

    }
    @PostMapping("/cancle/{id}")
    public JsonResult cancle(@PathVariable Long id){
        log.debug("取消申请单: {}",id);
        applicationService.cancle(id);
        log.debug("取消成功");
        return JsonResult.ok();
    }
    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distributeVehicle(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆: {}",applicationId);
        applicationService.distribut(applicationId,vehicleId);
        log.debug("分配成功");
        return JsonResult.ok();
    }
    @PostMapping("/backCar/{id}/{vehicleId}")
    public JsonResult backCar(@PathVariable Long id,@PathVariable Long vehicleId){
        log.debug("还车: {}{}",id,vehicleId);
        applicationService.backCar(id,vehicleId);
        log.debug("还车成功");
        return JsonResult.ok();
    }
}
